#####################
#   character
#   by Jerry Yang      
#   UUZ0225          
####################
from random import randrange
from bcolors import Bcolors
import skill
import math
import time

class Character():
    def __init__(self,inf):
        self.inf = inf
        
    def blood(self):
        level = self['Level']
        blood_volume = level*100
        self['Hp'] = blood_volume
        return(self)
    
    def exp(self):
        level = self['Level']
        exp_volume = level*10
        self['ExpMax'] = exp_volume
        return(self)
    
    def hurt(self,enemy_attack):
        blood_minute = math.ceil(enemy_attack*0.1) - math.ceil(self['Defend']*0.1)
#        print(Bcolors.FAIL)
        if blood_minute >= 0:
            print('You get '+str(blood_minute)+' hurt!')
            time.sleep(1)
        elif blood_minute < 0:
            blood_minute = 0
            print('You get '+str(blood_minute)+' hurt!')
            time.sleep(1)
        self['Hp'] -= blood_minute
        print('Your HP is ' + str(self['Hp']) + ' now!\n')
        time.sleep(1)
#        print(Bcolors.NORMALLY)
        if self['Hp'] <= 0:
            a = input('You are dead! Please press any key to try again.')
            while a:
                exit
        return(self)
    
    def use_magic(self,magic_use):
        magic_now = self['Magic']
        if magic_now-magic_use < 0:
#            print('Your magic is not enough!')
            Flag_skill = False
        elif  magic_now-magic_use >= 0:
            self['Magic'] -= magic_use
            Flag_skill = True
        return(self,Flag_skill)
    
    def get_exp(self,enemy_level):
        gain_exp = enemy_level*5
        exp_volume = self['Level']*10
        exp_pr = gain_exp + self['Exp']
        if exp_pr < exp_volume:
            self['Exp'] = exp_pr
        elif exp_pr >= exp_volume:
            print('Congratulations! Level up!')
            self['Level'] += 1
            self['Exp'] = exp_pr-exp_volume
            self['Attack'] += 1
            self['Magic'] += 1
            if self['Lucky'] <= 100:
                self['Lucky'] += 1
            if self['Defend'] <= 100:
                self['Defend'] += 1
        inf = Character.exp(self)
        return(inf)
    
    def get_skill(self,Skill):
        lucky_num = randrange(1,100)
        if lucky_num in range(1,self['Lucky']):
            Skill = skill.SkillInf(self,Skill)
        if len(Skill) >= 5:
            skill.get_SkillInformation(Skill)
            a = input('Too many skills! Please choose a number to remove a skill:')
            els = list(Skill.items())
            els_del = els[int(a)-1]
            del Skill[els_del[0]]
            print('Skills now：')
            skill.get_SkillInformation(Skill)
        return Skill









